<?php
namespace Home\Controller;
use Think\Controller;
class PublicController extends Controller {
    public function login(){
        $this->display();
    }

    public function loginAct(){
        $userName = I('post.username');
        $password = I('post.password');

        $User = M('User');
        $res = $User->where(['user_name'=>$userName,'password'=>md5($password)])->find();
        if($res){
            //判断是否为管理员
            session('user_id',$res['id']);
            session('real_name',$res['real_name']);
            session('user_name',$res['user_name']);
            session('auth',$res['auth']);
            if($res['auth'] == 'admin'){
                $this->redirect('User/index');
            }else{
                $this->redirect('Elfinder/index');
            }

        }else{
            $this->error('用户名或密码错误');
        }


    }

    public function logOut(){
        session(null);
        $this->redirect('Public/login');
    }
}